register ucsb.appscale.protoBuff.jar
register /root/software/apache-cassandra-0.7.4-src/lib/commons-lang-2.4.jar
register /root/software/apache-cassandra-0.7.4-src/lib/libthrift-0.5.jar
register /root/appscale/AppServer_Java/appengine-java-sdk-repacked/lib/impl/appengine-api.jar
register /root/software/apache-cassandra-0.7.4-src/lib/google-collections-1.0.jar

/*
Shopping: (customer, product, price, date)
*/

rows = LOAD 'cassandra://ks_shopping_1000000/Standard1' USING org.apache.cassandra.hadoop.pig.CassandraStorage();
entityRows = filter rows by $0 matches 'shoplist___Shopping___1/shoplist/Shopping.*';
entity = foreach entityRows generate ucsb.appscale.protoBuff.Parse($1);
transactions = foreach entity generate $0#'customer' as customer, $0#'price' as price;
buying = GROUP transactions by (chararray)customer;
-- Here had to convert from bytearray to a double
customer_record = foreach buying generate group, SUM((bag{tuple(double)})transactions.price) as expense;
sorted_customer_record = order customer_record by expense desc;
top_customer_record = limit sorted_customer_record 100;
store top_customer_record into 'shopping_vipCustomer' using PigStorage('\t');
